package com.pet.server.ext.util;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;

import com.pet.server.ext.Config;

public class Parameters {
    
    public static String WEB_BASE_URL = Config.getValue("image.url");
    
   
    public String getCookieString(){
    	return "hua1000pass="+getMyCookieValue();
    }
    
    public void setMyCookieValue(String myCookieValue) {
        this.myCookieValue = myCookieValue;
    }
    
    public String getMyCookieValue() {
        return this.myCookieValue;
    }
    
    public void setUploadException(Exception e) {
        uploadException = e;
    }
    
    public boolean hasUploadException() {
        return uploadException != null;
    }
    
    public void addFile(String key, String uri, byte[] fileBinary) {
        fileData.put(key, fileBinary);
        files.put(key, uri);
    }
    
    public void addField(String key, String value) {
        fields.put(key, value);
    }
    public void addArray(String key,String[] values){
    	arrays.put(key, values);
    }
    public Set<String> getFileKeys() {
        return files.keySet();
    }

    public String getFileUri(String key) {
        return files.get(key);
    }

    public String getFileUrl(String key) {
    	String uri = getFileUri(key);
        return uri!=null?WEB_BASE_URL+uri:null;
    }

    public byte[] getFileData(String key) {
        return fileData.get(key);
    }
        
    public Set<String> getFieldKeys() {
        return fields.keySet();
    }

    public Map<String, String> getFieldKeyValues() {
        return new HashMap<String, String>(fields);
    }
    public Map<String, String[]> getFieldsKeyValues() {
        return new HashMap<String, String[]>(arrays);
    }

    public String getFieldValue(String key) {
        return fields.get(key);
    }

    public Set<String> getFileUrls() {
        return new HashSet<String>(files.values());
    }

    public String toString() {
        return files.toString()+","+fields.toString();
    }

	public HttpServletRequest getRequest() {
		return request;
	}

	public void setRequest(HttpServletRequest request) {
		this.request = request;
	}

	private HashMap<String, String> fields = new HashMap<String, String>();
	private HashMap<String, String[]> arrays = new HashMap<String, String[]>();
    private HashMap<String, String> files = new HashMap<String, String>();
    private HashMap<String, byte[]> fileData = new HashMap<String, byte[]>();
    private Exception uploadException = null;
    private HttpServletRequest request;
    private String myCookieValue = null;
}
